package com.pms.dao;



import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.pms.entity.File;
import com.pms.entity.Folder;
import com.pms.util.DBHelp;
import com.pms.util.RowMapper;



public class FileDao {

	DBHelp<File> db=new DBHelp<File>();
	
	
	
	
	public void delFiletype(String id) {
		
		String sql="delete from filetype where id=?";
		db.executeSQL(sql,id);
	}




	public List<File> findByfdId(String fdid) {
		String sql="SELECT `t_file`.`fileid`,`t_file`.`name`,`t_file`.`size`,`t_user`.`username` FROM `t_file` LEFT JOIN `t_user` ON `t_file`.`t_user_useid`=`t_user`.`useid` WHERE `t_file`.`t_folder_id`=?";
		
		
		return db.executeQueryToList(sql, new RowMapper<File>(){

			@Override
			public File mapRow(ResultSet rs) throws SQLException {
				File f=new File();
				f.setFileid(rs.getString("fileid"));
				f.setFilename(rs.getString("name"));
				f.setSize(rs.getString("size"));
				f.setUsername(rs.getString("username"));
				
				return f;
			}
			
			
			
			
		}, fdid);
	}


	public void save(Folder fd) {
		
		String sql="INSERT INTO t_folder (`name`,t_project_proid,t_user_useid) VALUE(?,?,?)";
		db.executeSQL(sql, fd.getName(),fd.getProid(),fd.getUsreid());
		
	}




	public File save(File f) {
		String sql="INSERT INTO `t_file` (`name`,`t_folder_id`,t_user_useid) VALUE(?,?,?)";
		db.executeSQL(sql,f.getFilename(),f.getFolderid(),f.getUserid());
		
		return null;
	}}
